package com.itdaqi.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.server.ServerWebExchange;

/**
 * @Author Daqi
 * @Date 2020/12/10 19:03
 * @Version 1.0
 */
@Configuration
public class GulimallCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //配置跨域信息
        // 1、允许那种跨域请求
        corsConfiguration.addAllowedHeader("*");
        // 2、允许那种跨域方式
        corsConfiguration.addAllowedMethod("*");
        // 3、允许那种跨域请求来源
        corsConfiguration.addAllowedOrigin("*");
        // 4、是否允许跨域cooker信息
        corsConfiguration.setAllowCredentials(true);
        //注册跨域的配置
        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(source);

    }

}
